//
//  PMineResumeHeaderView.m
//  Btpin
//
//  Created by Vic on 2019/3/24.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PMineResumeHeaderView.h"
#import "PSShowTextCell.h"

@interface PMineResumeHeaderView ()<PSShowTextCellDelegate>
{
    UILabel *nameLbl;
    UILabel *baseInfoLbl;
    UIImageView *headerImgView;
    
    UILabel *jobLbl;
    UILabel *phoneLbl;
    UILabel *emailLbl;
    UIImageView *wxQRImgView;
    UILabel *wxIDLbl;
    
    PSShowTextCell *specialtyCell;
    PSShowTextCell *currentStatusCell;
}
@end

@implementation PMineResumeHeaderView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target infoData:(PMineResumeInfoModel *)infoModel {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUIWithInfoData:infoModel];
        self.delegate = target;
    }
    return self;
}
- (void)initUIWithInfoData:(PMineResumeInfoModel *)infoModel {
    UIView *topBgView = [UIToolsControl initViewWithFrame:CGRectMake(30*Scale, 0, WIDTH-60, 95*Scale) backgroundColor:COLOR_OF_WHITE];
    [self addSubview:topBgView];
    [topBgView borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
    CGFloat nameWidth = [UIToolsControl textWidth:(infoModel.name?infoModel.name:UD_GetOForK(isUserName)) size:CGSizeMake(MAXFLOAT, 35*Scale) font:Font_27]+10*Scale;
    nameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 20*Scale, nameWidth, 35*Scale) text:infoModel.name textColor:THEMECOLOR_OF_TEXT_333333 font:Font_27];
    nameLbl.font = FontBold(Font_27);
    [topBgView addSubview:nameLbl];
    
    baseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(nameLbl), EndY(nameLbl), 260*Scale, 25*Scale) text:[NSString stringWithFormat:@"%@ %@ %@ %@", (infoModel.residence?infoModel.residence:@""), (infoModel.age?infoModel.age:@""), (infoModel.education_cn?infoModel.education_cn:@""), (infoModel.experience_cn?infoModel.experience_cn:@"")] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [topBgView addSubview:baseInfoLbl];
    
    UIImageView *editImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(EndX(nameLbl), 30*Scale, 16*Scale, 15*Scale) imageName:@"mine_edit"];
    [topBgView addSubview:editImgView];
    
    headerImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(ViewWidth(topBgView)-66*Scale, 20*Scale, 66*Scale, 66*Scale) imageName:@"header_bg"];
    headerImgView.contentMode = UIViewContentModeScaleAspectFill;
    headerImgView.layer.cornerRadius = 33*Scale;
    headerImgView.layer.masksToBounds = YES;
    [topBgView addSubview:headerImgView];
    if (infoModel.avatar && infoModel.avatar.length) {
        [headerImgView sd_setImageWithURL:[NSURL URLWithString:infoModel.avatar]];
    }
    
    jobLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(topBgView)+10*Scale, 200*Scale, 25*Scale) text:[NSString stringWithFormat:@"曾任：%@", (infoModel.position?infoModel.position:@"")] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:jobLbl];
    
    phoneLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(jobLbl), EndY(jobLbl), ViewWidth(jobLbl), ViewHeight(jobLbl)) text:[NSString stringWithFormat:@"电话：%@", (infoModel.telephone?infoModel.telephone:@"")] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:phoneLbl];
    
    emailLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(jobLbl), EndY(phoneLbl), ViewWidth(jobLbl), ViewHeight(jobLbl)) text:[NSString stringWithFormat:@"邮箱：%@", (infoModel.email?infoModel.email:@"")] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:emailLbl];
    
    wxQRImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(self.frame.size.width-88*Scale, EndY(topBgView)+10*Scale, 58*Scale, 58*Scale) imageName:@"wx_bg"];
    [self addSubview:wxQRImgView];
    wxQRImgView.backgroundColor = THEMECOLOR_OF_GRAY;
    if (infoModel.weixin_img && infoModel.weixin_img.length) {
        [wxQRImgView sd_setImageWithURL:[NSURL URLWithString:infoModel.weixin_img]];
    } else {
        wxQRImgView.image = [UIImage imageNamed:@"wx_bg"];
    }
    
    wxIDLbl = [UIToolsControl initLabelWithFrame:CGRectMake(self.frame.size.width-230*Scale, EndY(wxQRImgView), 200*Scale, ViewHeight(jobLbl)) text:[NSString stringWithFormat:@"微信：%@", (infoModel.weixin?infoModel.weixin:@"")] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_12];
    wxIDLbl.textAlignment = NSTextAlignmentRight;
    [self addSubview:wxIDLbl];
    
    UIButton *editBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, 0, WIDTH, 180*Scale) imageName:nil target:self action:@selector(editBtnTap) title:nil titleColor:nil];
    [self addSubview:editBtn];
    
    specialtyCell = [[PSShowTextCell alloc] initWithFrame:CGRectMake(StartX(topBgView), EndY(emailLbl)+10*Scale, ViewWidth(topBgView), 60*Scale) target:self psShowTextCellType:PSShowTextCellTypeOfPrimaryTitle text:@"自我描述" detail:nil showIcon:NO rightText:((infoModel.specialty && infoModel.specialty.length)?@"已填写":@"请填写") showBottomLine:YES addBtn:YES];
    [self addSubview:specialtyCell];
    
    currentStatusCell = [[PSShowTextCell alloc] initWithFrame:CGRectMake(StartX(topBgView), EndY(specialtyCell), ViewWidth(topBgView), ViewHeight(specialtyCell)) target:self psShowTextCellType:PSShowTextCellTypeOfPrimaryTitle text:@"求职状态" detail:nil showIcon:NO rightText:((infoModel.current_cn && infoModel.current_cn.length)?infoModel.current_cn:@"请选择") showBottomLine:YES addBtn:YES];
    [self addSubview:currentStatusCell];
    
    UILabel *titleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, EndY(currentStatusCell)+10*Scale, WIDTH-60*Scale, 35*Scale) text:@"求职意向" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_17];
    [self addSubview:titleLbl];
    titleLbl.font = FontBold(Font_17);
}
- (void)editBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pMineResumeHeaderViewBaseInfoEdit)]) {
        [self.delegate pMineResumeHeaderViewBaseInfoEdit];
    }
}
- (void)psShowTextCellTap:(PSShowTextCell *)psShowTextCell {
    if (psShowTextCell == specialtyCell) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(pMineResumeHeaderViewBaseInfoSpecialty)]) {
            [self.delegate pMineResumeHeaderViewBaseInfoSpecialty];
        }
    } else {
        if (self.delegate && [self.delegate respondsToSelector:@selector(pMineResumeHeaderViewBaseInfoCurrentStatus)]) {
            [self.delegate pMineResumeHeaderViewBaseInfoCurrentStatus];
        }
    }
}
- (void)reloadDataForSpecialty:(NSString *)specialty {
    [specialtyCell reloadDataForRightText:specialty];
}

@end
